﻿/*
 *
 * DX_SourceOutliner
 * Copyright (C)2009
 * http://code.google.com/p/dxcsourceoutliner
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.CodeRush.StructuralParser;
using DevExpress.CodeRush.Core;
using System.Drawing;
using DevExpress.CodeRush.PlugInCore;

namespace DX_SourceOutliner
{
    internal class SourceCodeEditor
    {
        private LocatorBeacon _locatorBeacon;

        private void SelectCurrentElement()
        {
            //CodeRush.Selection.SelectWord();
        }

        public void NavigateToSelectedElement(LanguageElement selectedElement, bool hightLightElementLine)
        {
            if (selectedElement == null)
                return;

            CodeRush.Navigation.Navigate(selectedElement);

            if (hightLightElementLine)
                SelectCurrentLine();
            else
            {
                _locatorBeacon.Duration = 300;
                _locatorBeacon.Color = DevExpress.DXCore.Platform.Drawing.Color.ConvertFrom(Color.SlateBlue);
                _locatorBeacon.Start(CodeRush.TextViews.Active, CodeRush.Caret.Line, CodeRush.Caret.Offset);

                SelectCurrentElement();
            }
        }

        private void SelectCurrentLine()
        {
            CodeRush.Selection.SelectRange(CodeRush.Caret.Line, CodeRush.TextViews.Active.Width, CodeRush.Caret.Line, 1);
            //SourceRange range = new SourceRange(CodeRush.Caret.Line, CodeRush.TextViews.Active.Width, CodeRush.Caret.Line, 1);
            //TextHighlighter.PaintUnfocused(CodeRush.TextViews.Active, range, Color.Empty, Color.FromArgb(64, Color.Blue));
        }

        /// <summary>
        /// Initializes a new instance of the SourceCodeEditor class.
        /// </summary>
        /// <param name="locatorBeacon"></param>
        public SourceCodeEditor(LocatorBeacon locatorBeacon)
        {
            _locatorBeacon = locatorBeacon;
        }
    }
}
